-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ByteStr
and ByteString
types
#135073
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
b539a8c
to
f035281
Compare
This comment has been minimized.
This comment has been minimized.
Implement `ByteStr` and `ByteString` types Approved ACP: rust-lang/libs-team#502 Tracking issue: rust-lang#134915 These types represent human-readable strings that are conventionally, but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using escape sequences, and the `Display` impl uses the Unicode replacement character. This is a minimal implementation of these types and associated trait impls. It does not add any helper methods to other types such as `[u8]` or `Vec<u8>`. I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`, when those would be the second implementation for a type (counting the `T` impl), to avoid potential inference failures. We can attempt to add more impls later in standalone commits, and run them through crater. In addition to the `bstr` feature, I've added a `bstr_internals` feature for APIs provided by `core` for use by `alloc` but not currently intended for stabilization. This API and its implementation are based *heavily* on the `bstr` crate by Andrew Gallant (`@BurntSushi).` r? `@BurntSushi`
☀️ Try build successful - checks-actions |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Well, that's definitive. This is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
Was there discussion on ByteStr
verus BStr
? I guess the latter is a bit more opaque, so I think ByteStr
is probably the right choice for std. I do like the succinctness of BStr
though. (And similarly for ByteString
versus BString
.)
Could an |
Thank you!
I like the succinctness of BStr and BString as well, but others in the libs-api meeting felt those were too opaque. The deciding factor that led me to not push further for the shorter names was that the longer names don't conflict with the bstr crate, making it safer to (for instance) place them in the prelude in the future, and making it easier for crates that need to provide impls for both. |
Sure, I can do that. |
I noticed that |
@Skgland No objection to adding that, but that would be a complex change on top of this, so I would prefer to defer it to another PR. |
@bors r+ |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#135073 (Implement `ByteStr` and `ByteString` types) - rust-lang#135492 (Add missing check for async body when suggesting await on futures.) - rust-lang#135766 (handle global trait bounds defining assoc types) - rust-lang#135880 (Get rid of RunCompiler) - rust-lang#135908 (rustc_codegen_llvm: remove outdated asm-to-obj codegen note) - rust-lang#135911 (Allow `arena_cache` queries to return `Option<&'tcx T>`) - rust-lang#135920 (simplify parse_format::Parser::ws by using next_if) r? `@ghost` `@rustbot` modify labels: rollup
Approved ACP: rust-lang/libs-team#502
Tracking issue: #134915
These types represent human-readable strings that are conventionally,
but not always, UTF-8. The
Debug
impl prints non-UTF-8 bytes usingescape sequences, and the
Display
impl uses the Unicode replacementcharacter.
This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as
[u8]
or
Vec<u8>
.I've omitted a few implementations of
AsRef
,AsMut
,Borrow
,From
, andPartialOrd
, when those would be the second implementationfor a type (counting the
T
impl) or otherwise may cause inferencefailures. These impls are important, but we can attempt to add them
later in standalone commits, and run them through crater.
In addition to the
bstr
feature, I've added abstr_internals
featurefor APIs provided by
core
for use byalloc
but not currentlyintended for stabilization.
This API and its implementation are based heavily on the
bstr
crateby Andrew Gallant (@BurntSushi).
r? @BurntSushi